<?php
require_once 'classdb.php';
include("class.phpmailer.php");
include("class.smtp.php");
    class tin extends db
    {
        function laylienhetructuyen()
        {
            return $this->get_by_thutu("lienhe");
        }
		
		function laychamsocda($id=-1,$limit='')
        {
            return $this->get_by_thutu("chamsocda",$id,1,'',$limit);
        }
		function laydichvukhac($id=-1,$limit='')
        {
            return $this->get_by_thutu("dichvu",$id,1,'',$limit);
        }
		function laytintuc($id)
        {
            return $this->get_by_thutu("tintuc",$id,1);
        }
		function laythongtinkhac($id)
        {
            return $this->get_by_thutu("thongtinkhac",$id,1);
        }
		function laydanhmucsanpham()
        {
            return $this->get_by_thutu("tin_theloai",-1,1);
        }
		function laytuvan($id=-1)
        {
            return $this->get_by_thutu("tuvan",$id,1," and traloi <>'' ");
        }
		function laysanphammoi($id=-1,$limit='')
        {
            return $this->get_by_thutu("sanpham",$id,1,"",$limit);
        }
		function laysanpham($top=-1,$noibat=-1,$banchay=-1,$limit='')
        {
            return $this->get_by_thutu("sanpham",-1,1,"and(top='$top' or '$top'=-1) and(noibat='$noibat' or '$noibat'=-1) and(banchay='$banchay' or '$banchay'=-1)",$limit);
        }
		
		function laysanphamtheodanhmuc($idsanpham)
		{
			return $this->get_by_thutu("tin",-1,1,"and idloai='$idsanpham'",$limit);
		}
		
		
		function laysanphamphantrang($pageNum=1,$pageSize=9,&$totalRows,$tukhoa='',$idloailop=-1,$idloai=-1)
		{
		return $this->get_phantrang_db($pageNum,$pageSize,$totalRows,"sanpham", -1, 1, "and ten_vi like '%$tukhoa%' and (idloailop='$idloailop' or '$idloailop'=-1) and (idloai='$idloai' or '$idloai'=-1)",'');
		}
		function layquangcao($vitri)
		{
			return $this->get_by_thutu("quangcao",-1,1," and vitri='$vitri'");
		}
		function laytable($id)
		{
			return $this->get_by_thutu("field",$id);
		}
		function laysanphamkhac($table,$id)
		{
			$sql="select * from $table where id<>'$id' order by rand() limit 0,6";
			$kq=mysql_query($sql) or die(mysql_error());
			return $kq;
		}

        function send_mail($fromname,$to,$body) {
	$mail = new PHPMailer();
	$mail->IsSMTP(); // set mailer to use SMTP
	$mail->Host = "smtp.gmail.com"; // specify main and backup server
	$mail->Port = 465; // set the port to use
	$mail->SMTPAuth = true; // turn on SMTP authentication
	$mail->SMTPSecure = 'ssl';
	$mail->Username = "hethongtranhtheu@gmail.com"; // your SMTP username or your gmail username dia
	$mail->Password = "HeThongemail"; // your SMTP password or your gmail password
	$from = ""; // Reply to this email
	//$to="lilyngoc.hoang9@gmail.com"; // Recipients email ID enquiry@vietnamtourism-jsc.com
	$name=""; // Recipient's name
	$mail->From = $from;
	$mail->FromName = $fromname; // Name to indicate where the email came from when the recepient received
	$mail->AddAddress($to,$name);
	//$mail->AddReplyTo($from,"Vo Duy Tuan");
	$mail->WordWrap = 50; // set word wrap
	$mail->IsHTML(true); // send as HTML
	$mail->Subject = "Khach hang lien he";
	//echo $body; die;
	$mail->Body = $body; //HTML Body
	$mail->AltBody = ""; //Text Body
	//$mail->SMTPDebug = 2;
	$mail->Send();
    }
    }

?>
